def is_prime(n: int) -> bool:
    for i in range(2, n):
        if n % i == 0:
            return False
    return True

def get_nearest_small(n: int) -> int:
    while not is_prime(n - 1):
        n -= 1
    return n - 1

def get_nearest_big(n: int) -> int:
    while not is_prime(n):
        n += 1
    return n

result = {
    "one": 1,
    "two": 2,
    "three": 3,
    "four": 4,
    "five": 5,
    "six": 6,
    "seven": 7,
    "eight": 8,
    "nine": 9,
    "zero": 0
}
try:
    s1, s2, s3 = input().split()
except ValueError as _:
    print("Wrong input")
    exit()
if s1 not in result or s2 not in result or s3 not in result:
    print("Wrong input")
    exit()

to_find = result[s1] * 100 + result[s2] * 10 + result[s3]
bigger = get_nearest_big(to_find)
smaller = get_nearest_small(to_find)

if abs(to_find - bigger) < abs(to_find - smaller):
    print(bigger)
else:
    print(smaller)

